package com.io.copys;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Example02 {
    public static void main(String[] args) {
        System.out.println("知识点回顾");
    }

    @Test
    public void copy() {
        // 文件复制操作
        // 使用 FileReader 和 FileWriter 复制文件 字符操作

        String filePath = "E:\\test\\a.txt";
        String copyFilePath = "D:\\a.txt";

        // 1.创建输入流 和输出流
        FileReader fileReader = null;
        FileWriter fileWriter = null;
        char[] buf = new char[1024];
        int len = 0;
        try {
            // 读
            fileReader = new FileReader(filePath);
            // 写
            fileWriter = new FileWriter(copyFilePath);

            // 循环读写
            while ((len = fileReader.read()) != -1) {
                // 写入内容
                fileWriter.write(len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileReader != null || fileWriter != null) {
                try {
                    fileReader.close();
                    fileWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }


}
